/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.oki;

import org.ontspace.oki.owl.OspaceOKISerializedLomImpl;
import org.ieee.ltsc.datatype.impl.DurationImpl.DescriptionImpl.StringImpl;
import org.ieee.ltsc.datatype.impl.DurationImpl.DescriptionImpl.StringImpl.LanguageImpl;
import org.ieee.ltsc.lom.impl.LOMImpl;
import org.ieee.ltsc.lom.LOM;

/**
 * Creates a new instance of OspaceOKIOriginalLom
 */
public class OspaceOKIOriginalLom {

    OspaceOKISerializedLomImpl Slom;

    /**
     * Creates a new instance of original learning object 
     * using the serialized learning object 
     * @param l the serialized learning object
     */
    public OspaceOKIOriginalLom(OspaceOKISerializedLomImpl l) {
        Slom = l;
    }

    /**
     * Builds the non serialized learning object
     * @return the original learning object
     * @throws java.text.ParseException
     */
    public LOM BuildLom() throws java.text.ParseException {
        LOMImpl lom = new LOMImpl();

        // GENERAL 
        if (Slom.hasGeneral()) {
            LOMImpl.General general = lom.newGeneral();

            // 1.1 General Identifier
            for (int i = 0; i < Slom.getGeneralIdentifierCatalog().length; i++) {
                LOMImpl.General.Identifier identifier = general.newIdentifier(i);
                LOMImpl.General.Identifier.CatalogImpl catalogI = identifier.newCatalog();
                catalogI.setString(Slom.getGeneralIdentifierCatalog()[i]);
                LOMImpl.General.Identifier.EntryImpl entryIA = identifier.newEntry();
                entryIA.setString(Slom.getGeneralIdentifierEntry()[i]);
            }
            // 1.2 General Title
            for (int i = 0; i < Slom.getGeneralTitleString().length; i++) {
                LOMImpl.General.Title title = general.newTitle();
                LOMImpl.General.Title.StringImpl stringTitle = title.newString(i);
                stringTitle.setString(Slom.getGeneralTitleString()[i]);
                LOMImpl.General.Title.String.LanguageImpl langTitle = stringTitle.newLanguage();
                langTitle.setValue(Slom.getGeneralTitleLanguage()[i]);
            }
            // 1.3 General Language   
            for (int i = 0; i < Slom.getGeneralLanguage().length; i++) {
                LOMImpl.General.Language language = general.newLanguage(i);
                language.setString(Slom.getGeneralLanguage()[i]);
            }
            // 1.4 General Descritpion
            for (int i = 0; i < Slom.getNumberGeneralDescriptions(); i++) {
                LOMImpl.General.Description description = general.newDescription(i);
                for (int j = 0; j < Slom.getGeneralDescriptionString()[i].length; j++) {
                    LOMImpl.General.Description.StringImpl stringDescription = description.newString(j);
                    stringDescription.setString(Slom.getGeneralDescriptionString()[i][j]);
                    LOMImpl.General.Description.String.LanguageImpl langDescription = stringDescription.newLanguage();
                    langDescription.setValue(Slom.getGeneralDescriptionLanguage()[i][j]);
                }
            }
            // 1.5 General Keyword
            for (int i = 0; i < Slom.getNumberGeneralKeywords(); i++) {
                LOMImpl.General.Keyword keyword = general.newKeyword(i);
                for (int j = 0; j < Slom.getGeneralKeywordString()[i].length; j++) {
                    LOMImpl.General.Keyword.StringImpl stringKeyword = keyword.newString(j);
                    stringKeyword.setString(Slom.getGeneralKeywordString()[i][j]);
                    LOMImpl.General.Keyword.String.LanguageImpl langKeyword = stringKeyword.newLanguage();
                    langKeyword.setValue(Slom.getGeneralKeywordLanguage()[i][j]);
                }
            }
            // 1.6 General Coverage
            for (int i = 0; i < Slom.getNumberGeneralCoverages(); i++) {
                LOMImpl.General.Coverage coverage = general.newCoverage(i);
                for (int j = 0; j < Slom.getGeneralCoverageString()[i].length; j++) {
                    LOMImpl.General.Coverage.StringImpl stringCoverage = coverage.newString(j);
                    stringCoverage.setString(Slom.getGeneralCoverageString()[i][j]);
                    LOMImpl.General.Coverage.String.LanguageImpl langCoverage = stringCoverage.newLanguage();
                    langCoverage.setValue(Slom.getGeneralCoverageLanguage()[i][j]);
                }
            }
            // 1.7 General Structure
            if (!Slom.getGeneralStructureSource().equals("null") && !Slom.getGeneralStructureValue().equals("null")) {
                LOMImpl.General.Structure structure = general.newStructure();
                LOMImpl.General.Structure.SourceImpl sourceStructure = structure.newSource();
                sourceStructure.setString(Slom.getGeneralStructureSource());
                LOMImpl.General.Structure.ValueImpl valueStructure = structure.newValue();
                valueStructure.setString(Slom.getGeneralStructureValue());
            }

            // 1.8 General Aggregation Level
            if (!Slom.getGeneralAggregationLevelSource().equals("null") && !Slom.getGeneralAggregationLevelValue().equals("null")) {
                LOMImpl.General.AggregationLevel aggregationLevel = general.newAggregationLevel();
                LOMImpl.General.AggregationLevel.SourceImpl sourceAggregationLevel = aggregationLevel.newSource();
                sourceAggregationLevel.setString(Slom.getGeneralAggregationLevelSource());
                LOMImpl.General.AggregationLevel.ValueImpl valueAggregationLevel = aggregationLevel.newValue();
                valueAggregationLevel.setString(Slom.getGeneralAggregationLevelValue());
            }
        }
        // LIFE CYCLE
        if (Slom.hasLifeCycle()) {
            LOMImpl.LifeCycle lifeCycle = lom.newLifeCycle();

            // 2.1 LifeCycle Version
            for (int i = 0; i < Slom.getLifeCycleVersionString().length; i++) {
                LOMImpl.LifeCycle.Version version = lifeCycle.newVersion();
                LOMImpl.LifeCycle.Version.StringImpl stringVersion = version.newString(i);
                stringVersion.setString(Slom.getLifeCycleVersionString()[i]);
                LOMImpl.LifeCycle.Version.String.LanguageImpl langVersion = stringVersion.newLanguage();
                langVersion.setValue(Slom.getLifeCycleVersionLanguage()[i]);
            }
            // 2.2 LifeCycle Status
            if (!Slom.getLifeCycleStatusSource().equals("null") && !Slom.getLifeCycleStatusValue().equals("null")) {
                LOMImpl.LifeCycle.Status status = lifeCycle.newStatus();
                LOMImpl.LifeCycle.Status.SourceImpl sourceStatus = status.newSource();
                sourceStatus.setString(Slom.getLifeCycleStatusSource());
                LOMImpl.LifeCycle.Status.ValueImpl valueStatus = status.newValue();
                valueStatus.setString(Slom.getLifeCycleStatusValue());
            }

            // 2.3 LifeCycle Contribute

            for (int i = 0; i < Slom.getNumberLifeCycleContributes(); i++) {
                LOMImpl.LifeCycle.Contribute contribute = lifeCycle.newContribute(i);
                if (!Slom.getLifeCycleContributeRoleSource()[i].equals("null") || !Slom.getLifeCycleContributeRoleValue()[i].equals("null")) {
                    LOMImpl.ContributeElement.Role role = contribute.newRole();
                    LOMImpl.LifeCycle.Contribute.Role.SourceImpl sourceRole = role.newSource();
                    sourceRole.setString(Slom.getLifeCycleContributeRoleSource()[i]);
                    LOMImpl.LifeCycle.Contribute.Role.ValueImpl valueRole = role.newValue();
                    valueRole.setString(Slom.getLifeCycleContributeRoleValue()[i]);
                }
                if (Slom.getLifecycleContributeDateDateTime()[i] != null || Slom.getLifeCycleContributeDateDescriptionString()[i].length != 0) {
                    LOMImpl.ContributeElement.Date date = contribute.newDate();
                    if (Slom.getLifecycleContributeDateDateTime()[i] != null) {

                        LOMImpl.ContributeElement.Date.ValueImpl valueDate = date.newValue();
                        valueDate.setDateTime(Slom.getLifecycleContributeDateDateTime()[i]);
                    }
                    if (Slom.getLifeCycleContributeDateDescriptionString()[i].length != 0) {
                        LOMImpl.ContributeElement.Date.DescriptionImpl dateDescription = date.newDescription();

                        for (int j = 0; j < Slom.getLifeCycleContributeDateDescriptionString()[i].length; j++) {
                            //org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl
                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl stringDescription = dateDescription.newString(j);
                            stringDescription.setString(Slom.getLifeCycleContributeDateDescriptionString()[i][j]);

                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl.LanguageImpl languageDescription = stringDescription.newLanguage();
                            languageDescription.setValue(Slom.getLifeCycleContributeDateDescritionLanguage()[i][j]);

                        }
                    }
                }
                for (int j = 0; j < Slom.getLifeCycleContributeEntity()[i].length; j++) {
                    LOMImpl.ContributeElement.Entity entity = contribute.newEntity(i);
                    entity.setVCard(Slom.getLifeCycleContributeEntity()[i][j]);
                }


            }


        }
        // METAMETADATA
        if (Slom.hasMetaMetadata()) {
            LOMImpl.MetaMetadata metametadata = lom.newMetaMetadata();
            // 3.1 MetaMetadata Identifier
            for (int i = 0; i < Slom.getMetaMetadataIdentifierCatalog().length; i++) {
                LOMImpl.MetaMetadata.Identifier identifier = metametadata.newIdentifier(i);
                LOMImpl.MetaMetadata.Identifier.CatalogImpl catalogIdentifier = identifier.newCatalog();
                catalogIdentifier.setString(Slom.getMetaMetadataIdentifierCatalog()[i]);
                LOMImpl.MetaMetadata.Identifier.EntryImpl entryIdentifier = identifier.newEntry();
                entryIdentifier.setString(Slom.getMetaMetadataIdentifierEntry()[i]);
            }
            //3.2 MetaMetadata Contribute
            for (int i = 0; i < Slom.getNumberMetaMetadataContributes(); i++) {
                LOMImpl.MetaMetadata.Contribute contribute = metametadata.newContribute(i);
                //3.2.1 Contribute Role
                if (!Slom.getMetaMetadataContributeRoleSource()[i].equals("null") || !Slom.getMetaMetadataContributeRoleValue()[i].equals("null")) {
                    LOMImpl.ContributeElement.Role role = contribute.newRole();
                    LOMImpl.MetaMetadata.Contribute.Role.SourceImpl sourceRole = role.newSource();
                    sourceRole.setString(Slom.getMetaMetadataContributeRoleSource()[i]);
                    LOMImpl.MetaMetadata.Contribute.Role.ValueImpl valueRole = role.newValue();
                    valueRole.setString(Slom.getMetaMetadataContributeRoleValue()[i]);
                }
                //3.2.3 Contribute Date
                if (Slom.getMetaMetadataContriuteDateDatetime()[i] != null || Slom.getMetaMetadataContributeDateDescriptionString()[i].length != 0) {
                    LOMImpl.ContributeElement.Date date = contribute.newDate();
                    if (Slom.getMetaMetadataContriuteDateDatetime()[i] != null) {
                        LOMImpl.ContributeElement.Date.ValueImpl valueDate = date.newValue();
                        valueDate.setDateTime(Slom.getMetaMetadataContriuteDateDatetime()[i]);
                    }
                    if (Slom.getMetaMetadataContributeDateDescriptionString()[i].length != 0) {
                        LOMImpl.ContributeElement.Date.DescriptionImpl dateDescription = date.newDescription();

                        for (int j = 0; j < Slom.getMetaMetadataContributeDateDescriptionString()[i].length; j++) {
                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl stringDescription = dateDescription.newString(j);
                            stringDescription.setString(Slom.getMetaMetadataContributeDateDescriptionString()[i][j]);

                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl.LanguageImpl languageDescription = stringDescription.newLanguage();
                            languageDescription.setValue(Slom.getMetaMetadataContributeDateDescriptionLanguage()[i][j]);
                        }
                    }
                }

                //3.2.2 Contribute Entity
                for (int j = 0; j < Slom.getMetaMetadataContributeEntity()[i].length; j++) {
                    LOMImpl.ContributeElement.Entity entity = contribute.newEntity(j);
                    entity.setVCard(Slom.getMetaMetadataContributeEntity()[i][j]);
                }
            }
            //3.3 MetaMEtadata Schema
            for (int i = 0; i < Slom.getMetaMetadataSchema().length; i++) {
                LOMImpl.MetaMetadata.MetadataSchema schema = metametadata.newMetadataSchema(i);
                schema.setString(Slom.getMetaMetadataSchema()[i]);
            }
            //3.4 MetaMetadata Language
            if (!Slom.getMetaMetadataLanguage().equals("null")) {
                LOMImpl.MetaMetadata.Language language = metametadata.newLanguage();
                language.setString(Slom.getMetaMetadataLanguage());
            }
        }



        // TECHNICAL 


        if (Slom.hasTechnical()) {
            LOMImpl.Technical technical = lom.newTechnical();
            // 4.1 Technical Format
            for (int i = 0; i < Slom.getTechnicalFormat().length; i++) {
                LOMImpl.Technical.Format format = technical.newFormat(i);
                format.setString(Slom.getTechnicalFormat()[i]);
            }

            // 4.2 Technical Size
            if (!Slom.getTechnicalSize().equals("null")) {
                LOMImpl.Technical.Size size = technical.newSize();
                size.setString(Slom.getTechnicalSize());
            }
            // 4.3 Technical Location 
            for (int i = 0; i < Slom.getTechnicalLocation().length; i++) {
                LOMImpl.Technical.Location location = technical.newLocation(i);
                location.setString(Slom.getTechnicalLocation()[i]);
            }

            // 4.4 Technical Requirement
            for (int i = 0; i < Slom.getNumberTechnicalRequirements(); i++) {
                LOMImpl.Technical.Requirement requirement = technical.newRequirement(i);
                for (int j = 0; j < Slom.getNumberTechnicalRequirementOrComposites()[i]; j++) {
                    LOMImpl.Technical.Requirement.OrComposite orcomposite = requirement.newOrComposite(j);
                    if (!Slom.getTechnicalRequirementOrCompositeTypeSource()[i][j].equals("null") && !Slom.getTechnicalRequirementOrCompositeTupeValue()[i][j].equals("null")) {
                        LOMImpl.Technical.Requirement.OrComposite.Type type = orcomposite.newType();
                        LOMImpl.Technical.Requirement.OrComposite.Type.SourceImpl sourceType = type.newSource();
                        sourceType.setString(Slom.getTechnicalRequirementOrCompositeTypeSource()[i][j]);
                        LOMImpl.Technical.Requirement.OrComposite.Type.ValueImpl valueType = type.newValue();
                        valueType.setString(Slom.getTechnicalRequirementOrCompositeTupeValue()[i][j]);
                    }
                    if (!Slom.getTechnicalRequirementOrCompositeNameSource()[i][j].equals("null") && !Slom.getTechnicalRequirementOrCompositeNameValue()[i][j].equals("null")) {
                        LOMImpl.Technical.Requirement.OrComposite.Name name = orcomposite.newName();
                        LOMImpl.Technical.Requirement.OrComposite.Name.SourceImpl sourceName = name.newSource();
                        sourceName.setString(Slom.getTechnicalRequirementOrCompositeNameSource()[i][j]);
                        LOMImpl.Technical.Requirement.OrComposite.Name.ValueImpl valueName = name.newValue();
                        valueName.setString(Slom.getTechnicalRequirementOrCompositeNameValue()[i][j]);
                    }
                    if (!Slom.getTechnicalRequirementOrCompositeMinimumVersion()[i][j].equals("null")) {
                        LOMImpl.Technical.Requirement.OrComposite.MinimumVersion minimum = orcomposite.newMinimumVersion();
                        minimum.setString(Slom.getTechnicalRequirementOrCompositeMinimumVersion()[i][j]);
                    }
                    if (!Slom.getTechnicalRequirementOrCompositeMaximumVersion()[i][j].equals("null")) {
                        LOMImpl.Technical.Requirement.OrComposite.MaximumVersion maximum = orcomposite.newMaximumVersion();
                        maximum.setString(Slom.getTechnicalRequirementOrCompositeMaximumVersion()[i][j]);
                    }
                }
            }
            // 4.5 Technical Installation Remarks
            for (int i = 0; i < Slom.getTechnicalInstallationRemarksString().length; i++) {
                LOMImpl.Technical.InstallationRemarks installationRemarks = technical.newInstallationRemarks();
                LOMImpl.Technical.InstallationRemarks.StringImpl stringInstallationRemarks = installationRemarks.newString(i);
                stringInstallationRemarks.setString(Slom.getTechnicalInstallationRemarksString()[i]);
                LOMImpl.Technical.InstallationRemarks.String.LanguageImpl langInstallationRemarks = stringInstallationRemarks.newLanguage();
                langInstallationRemarks.setValue(Slom.getTechnicalInstallationRemarksLanguage()[i]);
            }
            // 4.6 Technical Other Platform Requirements
            for (int i = 0; i < Slom.getTechnicalOtherPlatformRequirementsString().length; i++) {
                LOMImpl.Technical.OtherPlatformRequirements otherPlatformRequirements = technical.newOtherPlatformRequirements();
                LOMImpl.Technical.OtherPlatformRequirements.StringImpl stringOtherPlatformRequirements = otherPlatformRequirements.newString(i);
                stringOtherPlatformRequirements.setString(Slom.getTechnicalOtherPlatformRequirementsString()[i]);
                LOMImpl.Technical.OtherPlatformRequirements.String.LanguageImpl langOtherPlatformRequirements = stringOtherPlatformRequirements.newLanguage();
                langOtherPlatformRequirements.setValue(Slom.getTechnicalOtherPlatformRequirementsLanguage()[i]);
            }
            // 4.7 Technical Duration  
            if (!Slom.getTechnicalDuration().equals("null") || (Slom.getTechnicalDuration().equals("null") && Slom.getTechnicalDurationDescriptionString().length != 0)) {
                LOMImpl.Technical.Duration duration = technical.newDuration();
                if (!Slom.getTechnicalDuration().equals("null")) {
                    LOMImpl.Technical.Duration.ValueImpl valueDuration = duration.newValue();
                    valueDuration.setDuration(Long.parseLong(Slom.getTechnicalDuration()));
                }
                if (Slom.getTechnicalDurationDescriptionString().length != 0) {
                    LOMImpl.Technical.Duration.DescriptionImpl durationDescription = duration.newDescription();

                    for (int i = 0; i < Slom.getTechnicalDurationDescriptionString().length; i++) {
                        LOMImpl.Technical.Duration.Description.StringImpl stringDescription = (StringImpl) durationDescription.newString(i);
                        stringDescription.setString(Slom.getTechnicalDurationDescriptionString()[i]);

                        LOMImpl.Technical.Duration.Description.String.LanguageImpl languageDescription = (LanguageImpl) stringDescription.newLanguage();
                        languageDescription.setValue(Slom.getTechnicalDurationDescriptionLanguage()[i]);

                    }
                }
            }
        }
        // EDUCATIONAL
        if (Slom.hasEducational()) {
            for (int i = 0; i < Slom.getNumberEducationals(); i++) {
                LOMImpl.Educational educational = lom.newEducational(i);

                // 5.1 Educational Interactivity Type
                if (!Slom.getEducationalInteractivityTypeValue()[i].equals("null") && !Slom.getEducationalInteractivityTypeSource()[i].equals("null")) {
                    LOMImpl.Educational.InteractivityType interactivityType = educational.newInteractivityType();
                    LOMImpl.Educational.InteractivityType.SourceImpl sourceInteractivityType = interactivityType.newSource();
                    sourceInteractivityType.setString(Slom.getEducationalInteractivityTypeSource()[i]);
                    LOMImpl.Educational.InteractivityType.ValueImpl valueInteractivityType = interactivityType.newValue();
                    valueInteractivityType.setString(Slom.getEducationalInteractivityTypeValue()[i]);
                }
                // 5.2 Educational Learning Resource Type
                for (int j = 0; j < Slom.getEducationalLearningResourceTypeSource()[i].length; j++) {
                    LOMImpl.Educational.LearningResourceType learningResourceType = educational.newLearningResourceType(j);
                    LOMImpl.Educational.LearningResourceType.SourceImpl sourceLearningResourceType = learningResourceType.newSource();
                    sourceLearningResourceType.setString(Slom.getEducationalLearningResourceTypeSource()[i][j]);
                    LOMImpl.Educational.LearningResourceType.ValueImpl valueLearningResourceType = learningResourceType.newValue();
                    valueLearningResourceType.setString(Slom.getEducationalLearningResourceTypeValue()[i][j]);
                }
                // 5.3 Educational Interactivity Level
                if (!Slom.getEducationalInteractivityLevelValue()[i].equals("null") && !Slom.getEducationalInteractivityLevelSource()[i].equals("null")) {
                    LOMImpl.Educational.InteractivityLevel interactivityLevel = educational.newInteractivityLevel();
                    LOMImpl.Educational.InteractivityLevel.SourceImpl sourceInteractivityLevel = interactivityLevel.newSource();
                    sourceInteractivityLevel.setString(Slom.getEducationalInteractivityLevelSource()[i]);
                    LOMImpl.Educational.InteractivityLevel.ValueImpl valueInteractivityLevel = interactivityLevel.newValue();
                    valueInteractivityLevel.setString(Slom.getEducationalInteractivityLevelValue()[i]);
                }
                // 5.4 Educational Semantic Density
                if (!Slom.getEducationalSemanticDensitySource()[i].equals("null") && !Slom.getEducationalSemanticDensityValue()[i].equals("null")) {
                    LOMImpl.Educational.SemanticDensity semanticDensity = educational.newSemanticDensity();
                    LOMImpl.Educational.SemanticDensity.SourceImpl sourceSemanticDensity = semanticDensity.newSource();
                    sourceSemanticDensity.setString(Slom.getEducationalSemanticDensitySource()[i]);
                    LOMImpl.Educational.SemanticDensity.ValueImpl valueSemanticDensity = semanticDensity.newValue();
                    valueSemanticDensity.setString(Slom.getEducationalSemanticDensityValue()[i]);
                }
                // 5.5 Educational Intended End User Role
                for (int j = 0; j < Slom.getEducationalIntendedEndUserRoleSource()[i].length; j++) {
                    LOMImpl.Educational.IntendedEndUserRole intendedEndUserRole = educational.newIntendedEndUserRole(j);
                    LOMImpl.Educational.IntendedEndUserRole.SourceImpl sourceIntendedEndUserRole = intendedEndUserRole.newSource();
                    sourceIntendedEndUserRole.setString(Slom.getEducationalIntendedEndUserRoleSource()[i][j]);
                    LOMImpl.Educational.IntendedEndUserRole.ValueImpl valueIntendedEndUserRole = intendedEndUserRole.newValue();
                    valueIntendedEndUserRole.setString(Slom.getEducationalIntendedEndUserRoleValue()[i][j]);
                }
                // 5.6 Educational Context
                for (int j = 0; j < Slom.getEducationalContextSource()[i].length; j++) {
                    LOMImpl.Educational.Context context = educational.newContext(j);
                    LOMImpl.Educational.Context.SourceImpl sourceContext = context.newSource();
                    sourceContext.setString(Slom.getEducationalContextSource()[i][j]);
                    LOMImpl.Educational.Context.ValueImpl valueContext = context.newValue();
                    valueContext.setString(Slom.getEducationalContextValue()[i][j]);
                }
                // 5.7 Educational Typical Age Range
                for (int j = 0; j < Slom.getNumberEducationalTypicalAgeRanges()[i]; j++) {
                    LOMImpl.Educational.TypicalAgeRange typicalAgeRange = educational.newTypicalAgeRange(j);
                    for (int k = 0; k < Slom.getEducationalTypicalAgeRangeString()[i][j].length; k++) {
                        LOMImpl.Educational.TypicalAgeRange.StringImpl stringTypicalAgeRange = typicalAgeRange.newString(k);
                        stringTypicalAgeRange.setString(Slom.getEducationalTypicalAgeRangeString()[i][j][k]);
                        LOMImpl.Educational.TypicalAgeRange.String.LanguageImpl languageTypicalAgeRange = stringTypicalAgeRange.newLanguage();
                        languageTypicalAgeRange.setValue(Slom.getEducationalTypicalAgeRangeLanguage()[i][j][k]);
                    }
                }
                // 5.8 Educational Difficulty
                if (!Slom.getEducationalDifficultySource()[i].equals("null") && !Slom.getEducationalDifficultyValue()[i].equals("null")) {
                    LOMImpl.Educational.Difficulty difficulty = educational.newDifficulty();
                    LOMImpl.Educational.Difficulty.SourceImpl sourceDifficulty = difficulty.newSource();
                    sourceDifficulty.setString(Slom.getEducationalDifficultySource()[i]);
                    LOMImpl.Educational.Difficulty.ValueImpl valueDifficulty = difficulty.newValue();
                    valueDifficulty.setString(Slom.getEducationalDifficultyValue()[i]);
                }
                // 5.9 Educational Typical Learning Time
                if (!Slom.getEducationalTypicalLearningTime()[i].equals("null") || (Slom.getEducationalTypicalLearningTimeDescriptionString()[i].length != 0)) {
                    LOMImpl.Educational.TypicalLearningTime typicalLearningTime = educational.newTypicalLearningTime();
                    if (!Slom.getEducationalTypicalLearningTime()[i].equals("null")) {
                        LOMImpl.Educational.TypicalLearningTime.ValueImpl valueTypicalLearningTime = typicalLearningTime.newValue();
                        valueTypicalLearningTime.setDuration(Long.parseLong(Slom.getEducationalTypicalLearningTime()[i]));
                    }
                    if (Slom.getEducationalTypicalLearningTimeDescriptionString()[i].length != 0) {
                        LOMImpl.Educational.TypicalLearningTime.DescriptionImpl timeDescription = typicalLearningTime.newDescription();

                        for (int j = 0; j < Slom.getEducationalTypicalLearningTimeDescriptionString()[i].length; j++) {
                            LOMImpl.Educational.TypicalLearningTime.Description.StringImpl stringDescription = (StringImpl) timeDescription.newString(j);
                            stringDescription.setString(Slom.getEducationalTypicalLearningTimeDescriptionString()[i][j]);

                            LOMImpl.Educational.TypicalLearningTime.Description.String.LanguageImpl languageDescription = (LanguageImpl) stringDescription.newLanguage();
                            languageDescription.setValue(Slom.getEducationalTypicalLearningTimeDescriptionLanguage()[i][j]);

                        }
                    }
                }

                // 5.10 Educational Description
                for (int j = 0; j < Slom.getNumberEducationalDescriptions()[i]; j++) {
                    LOMImpl.Educational.Description descriptionEducational = educational.newDescription(j);
                    for (int k = 0; k < Slom.getEducationalDescriptionString()[i][j].length; k++) {
                        LOMImpl.Educational.Description.StringImpl stringEDescription = descriptionEducational.newString(k);
                        stringEDescription.setString(Slom.getEducationalDescriptionString()[i][j][k]);
                        LOMImpl.Educational.Description.String.LanguageImpl langEDescription = stringEDescription.newLanguage();
                        langEDescription.setValue(Slom.getEducationalDescriptionLanguage()[i][j][k]);
                    }
                }
                // 5.11 Educational user Language
                for (int j = 0; j < Slom.getEducationalLanguage()[i].length; j++) {
                    LOMImpl.Educational.Language language = educational.newLanguage(j);
                    language.setString(Slom.getEducationalLanguage()[i][j]);
                }
            }
        }
        // RIGHTS


        if (Slom.hasRights()) {
            LOMImpl.Rights rights = lom.newRights();
            // 6.1 Rights Cost
            if (!Slom.getRightsCostSource().equals("null") && !Slom.getRightsCostValue().equals("null")) {
                LOMImpl.Rights.Cost cost = rights.newCost();
                LOMImpl.Rights.Cost.SourceImpl sourceCost = cost.newSource();
                sourceCost.setString(Slom.getRightsCostSource());
                LOMImpl.Rights.Cost.ValueImpl valueCost = cost.newValue();
                valueCost.setString(Slom.getRightsCostValue());
            }
            // 6.2 Rights Copyright and other restrictions
            if (!Slom.getRightsCopyRightAndOtherRestrictionsSource().equals("null") && !Slom.getRightsCopyRightAndOtherRestrictionsValue().equals("null")) {
                LOMImpl.Rights.CopyrightAndOtherRestrictions copyright = rights.newCopyrightAndOtherRestrictions();
                LOMImpl.Rights.CopyrightAndOtherRestrictions.SourceImpl sourceCopyright = copyright.newSource();
                sourceCopyright.setString(Slom.getRightsCopyRightAndOtherRestrictionsSource());
                LOMImpl.Rights.CopyrightAndOtherRestrictions.ValueImpl valueCopyright = copyright.newValue();
                valueCopyright.setString(Slom.getRightsCopyRightAndOtherRestrictionsValue());
            }
            // 6.3 Rights Description
            if (Slom.getRightsDescriptionString().length != 0) {
                LOMImpl.Rights.Description descriptionRights = rights.newDescription();
                for (int i = 0; i < Slom.getRightsDescriptionString().length; i++) {
                    LOMImpl.Rights.Description.StringImpl stringDescription = descriptionRights.newString(i);
                    stringDescription.setString(Slom.getRightsDescriptionString()[i]);
                    LOMImpl.Rights.Description.String.LanguageImpl langDescription = stringDescription.newLanguage();
                    langDescription.setValue(Slom.getRightsDescriptionLanguage()[i]);
                }
            }
        }

        //RELATION
        if (Slom.hasRelation()) {
            for (int i = 0; i < Slom.getNumberRelations(); i++) {
                LOMImpl.Relation relation = lom.newRelation(i);
                //7.1 Kind
                if (!Slom.getRelationKindSource()[i].equals("null") && !Slom.getRelationKindValue()[i].equals("null")) {
                    LOMImpl.Relation.Kind kind = relation.newKind();
                    LOMImpl.Relation.Kind.SourceImpl sourceKind = kind.newSource();
                    sourceKind.setString(Slom.getRelationKindSource()[i]);
                    LOMImpl.Relation.Kind.ValueImpl valueKind = kind.newValue();
                    valueKind.setString(Slom.getRelationKindValue()[i]);
                }

                //7.2 Resource
                if (Slom.getRelationResourceCatalog()[i].length != 0 || Slom.getRelationResourceEntry()[i].length != 0 || Slom.getRelationResourceDescriptionString()[i][0].length != 0) {
                    LOMImpl.Relation.Resource resource = relation.newResource();
                    for (int j = 0; j < Slom.getRelationResourceCatalog()[i].length; j++) {
                        LOMImpl.Relation.Resource.Identifier identifier = resource.newIdentifier(j);
                        LOMImpl.Relation.Resource.Identifier.CatalogImpl catalogId = identifier.newCatalog();
                        catalogId.setString(Slom.getRelationResourceCatalog()[i][j]);
                        LOMImpl.Relation.Resource.Identifier.EntryImpl entryId = identifier.newEntry();
                        entryId.setString(Slom.getRelationResourceEntry()[i][j]);
                    }
                    for (int j = 0; j < Slom.getNumberRelationDescriptions()[i]; j++) {
                        LOMImpl.Relation.Resource.Description description = resource.newDescription(j);
                        for (int k = 0; k < Slom.getRelationResourceDescriptionString()[i][j].length; k++) {
                            LOMImpl.Relation.Resource.Description.StringImpl stringDescription = description.newString(k);
                            stringDescription.setString(Slom.getRelationResourceDescriptionString()[i][j][k]);
                            LOMImpl.Relation.Resource.Description.String.LanguageImpl languageDescription = stringDescription.newLanguage();
                            languageDescription.setValue(Slom.getRelationResourceDescriptionLanguage()[i][j][k]);
                        }
                    }
                }
            }
        }


        //ANNOTATION
        if (Slom.hasAnnotation()) {
            for (int i = 0; i < Slom.getNumberAnnotations(); i++) {
                LOMImpl.Annotation annotation = lom.newAnnotation(i);
                //8.1 Entity
                if (Slom.getAnnotationEntity()[i] != null) {
                    LOMImpl.Annotation.Entity entity = annotation.newEntity();
                    entity.setVCard(Slom.getAnnotationEntity()[i]);
                }
                //8.2 Date
                if (Slom.getAnnotationDateDateTime()[i] != null || (Slom.getAnnotationDateDateTime()[i] == null && Slom.getAnnotationDateDescriptionString()[i].length != 0)) {
                    LOMImpl.Annotation.Date date = annotation.newDate();
                    if (Slom.getAnnotationDateDateTime()[i] != null) {
                        LOMImpl.Annotation.Date.ValueImpl valueDate = date.newValue();
                        valueDate.setDateTime(Slom.getAnnotationDateDateTime()[i]);
                    }
                    if (Slom.getAnnotationDateDescriptionString()[i].length != 0) {
                        LOMImpl.ContributeElement.Date.DescriptionImpl dateDescription = date.newDescription();

                        for (int j = 0; j < Slom.getAnnotationDateDescriptionString()[i].length; j++) {
                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl stringDescription = dateDescription.newString(j);
                            stringDescription.setString(Slom.getAnnotationDescriptionString()[i][j]);

                            org.ieee.ltsc.datatype.impl.LangStringImpl.StringImpl.LanguageImpl languageDescription = stringDescription.newLanguage();
                            languageDescription.setValue(Slom.getAnnotationDateDescriptionLanguage()[i][j]);

                        }
                    }
                }
                //8.3 Description
                if (Slom.getAnnotationDescriptionString()[i].length != 0) {
                    LOMImpl.Annotation.Description description = annotation.newDescription();
                    for (int j = 0; j < Slom.getAnnotationDescriptionString()[i].length; j++) {
                        LOMImpl.Annotation.Description.StringImpl stringDescription = description.newString(j);
                        stringDescription.setString(Slom.getAnnotationDescriptionString()[i][j]);
                        LOMImpl.Annotation.Description.String.LanguageImpl languageDescription = stringDescription.newLanguage();
                        languageDescription.setValue(Slom.getAnnotationDescriptionLanguage()[i][j]);
                    }
                }

            }
        }


        //CLASSIFICATION
        if (Slom.hasClassification()) {
            for (int i = 0; i < Slom.getNumberClassifications(); i++) {
                LOMImpl.Classification classification = lom.newClassification(i);
                //9.1 Purpose
                if (!Slom.getClassificationPurposeValue()[i].equals("null")) {
                    LOMImpl.Classification.Purpose purpose = classification.newPurpose();
                    LOMImpl.Classification.Purpose.SourceImpl sourcePurpose = purpose.newSource();
                    sourcePurpose.setString(Slom.getClassificationPurposeSource()[i]);
                    LOMImpl.Classification.Purpose.ValueImpl valuePurpose = purpose.newValue();
                    valuePurpose.setString(Slom.getClassificationPurposeValue()[i]);
                }
                //9.2 Taxon Paths
                for (int j = 0; j < Slom.getNumberClassificationTaxonPaths()[i]; j++) {
                    LOMImpl.Classification.TaxonPath taxonPath = classification.newTaxonPath(j);
                    if (Slom.getClassificationTaxonPathSourceString()[i][j].length != 0) {
                        LOMImpl.Classification.TaxonPath.Source source = taxonPath.newSource();
                        for (int k = 0; k < Slom.getClassificationTaxonPathSourceString()[i][j].length; k++) {
                            LOMImpl.Classification.TaxonPath.Source.StringImpl stringSource = source.newString(k);
                            stringSource.setString(Slom.getClassificationTaxonPathSourceString()[i][j][k]);
                            LOMImpl.Classification.TaxonPath.Source.String.LanguageImpl languageSource = stringSource.newLanguage();
                            languageSource.setValue(Slom.getClassificationTaxonPathSourceLanguage()[i][j][k]);
                        }
                    }
                    for (int k = 0; k < Slom.getClassificationTaxonPathSourceTaxonId()[i][j].length; k++) {
                        LOMImpl.Classification.TaxonPath.Taxon taxon = taxonPath.newTaxon(k);
                        if (!Slom.getClassificationTaxonPathSourceTaxonId()[i][j][k].equals("null")) {
                            LOMImpl.Classification.TaxonPath.Taxon.Id id = taxon.newId();
                            id.setString(Slom.getClassificationTaxonPathSourceTaxonId()[i][j][j]);
                        }
                        for (int l = 0; l < Slom.getClassificationTaxonPathSourceTaxonEntryString()[i][j][k].length; l++) {
                            LOMImpl.Classification.TaxonPath.Taxon.Entry entry = taxon.newEntry();
                            LOMImpl.Classification.TaxonPath.Taxon.Entry.StringImpl stringEntry = entry.newString(l);
                            stringEntry.setString(Slom.getClassificationTaxonPathSourceTaxonEntryString()[i][j][k][l]);
                            LOMImpl.Classification.TaxonPath.Taxon.Entry.String.LanguageImpl languageEntry = stringEntry.newLanguage();
                            languageEntry.setValue(Slom.getClassificationTaxonPathSourceTaxonEntryLanguage()[i][j][k][l]);
                        }
                    }

                }
                //9.3 Description
                if (Slom.getClassificationDescriptionString()[i].length != 0) {
                    LOMImpl.Classification.Description description = classification.newDescription();
                    for (int j = 0; j < Slom.getClassificationDescriptionString()[i].length; j++) {
                        LOMImpl.Classification.Description.StringImpl stringDescription = description.newString(j);
                        stringDescription.setString(Slom.getClassificationDescriptionString()[i][j]);
                        LOMImpl.Classification.Description.String.LanguageImpl languageDescription = stringDescription.newLanguage();
                        languageDescription.setValue(Slom.getClassificationDescriptionLanguage()[i][j]);
                    }
                }

                //9.4 Keyword
                for (int j = 0; j < Slom.getNumberClassificationKeywords()[i]; j++) {
                    LOMImpl.Classification.Keyword keyword = classification.newKeyword(j);
                    for (int k = 0; k < Slom.getClassificationKeywordString()[i][j].length; k++) {
                        LOMImpl.Classification.Keyword.StringImpl stringKeyword = keyword.newString(k);
                        stringKeyword.setString(Slom.getClassificationKeywordString()[i][j][k]);
                        LOMImpl.Classification.Keyword.String.LanguageImpl languageKeyword = stringKeyword.newLanguage();
                        languageKeyword.setValue(Slom.getClassificationKeywordLanguage()[i][j][k]);
                    }
                }
            }
        }
        LOM l = lom;
        return l;
    }
}
